package com.acme.bankapp.service.bank;

import com.acme.bankapp.domain.account.*;
import com.acme.bankapp.domain.bank.*;
import com.acme.bankapp.domain.client.*;
import com.acme.bankapp.exceptions.*;

public class BankApplication {
    static Bank bank = new Bank();

    public static void main(String[] args) {
        Bank bank = BankService.createNewBank();
        Client client1 = null;
        Client client2 = null;

        Account account1 = new SavingAccount(1, 100);
        Account account2 = new CheckingAccount(2, 100, 10);

        Account account3 = new SavingAccount(3, 50);
        Account account4 = new CheckingAccount(4, 75, 20);

        try {
            client1 = BankService.addClient(bank, "John", Gender.MALE);
            client2 = BankService.addClient(bank, "Miranda", Gender.FEMALE);
            client1.addAccount(account1);
            client1.addAccount(account2);
            client2.addAccount(account3);
            client2.addAccount(account4);
        } catch (ClientExistsException e) {
            e.printStackTrace();
        }

        account1.deposit(100);
        try {
            account3.withdraw(50);
            account4.withdraw(80);
        } catch (OverDraftLimitExceededException e) {
            System.out.println("!!!ERROR!!! CheckingAccount Exception:");
            System.out.println("!!!ERROR!!! Amount: " + e.getAccountBalance());
            System.out.println("!!!ERROR!!! Maximum amount to withdraw: " + e.maximumAmountToWithdraw());
            e.printStackTrace();
        } catch (NoEnoughFundsException e) {
            System.out.println("!!!ERROR!!!  SavingAccount");
            e.printStackTrace();
        }

        BankService.printBalance(bank);
        BankService.printMaximumAmountToWithdraw(bank);
    }
}
